//package com.plian.system.service.mt.impl;
//
//import cn.afterturn.easypoi.excel.ExcelImportUtil;
//import cn.afterturn.easypoi.excel.entity.ImportParams;
//import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
//import com.alibaba.excel.EasyExcel;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dao.sys.file.FileDao;
//import com.plian.system.dao.sys.user.UserDao;
//import com.plian.system.entity.mt.TemporaryTaskDistribution;
//import com.plian.system.entity.mt.TemporaryTaskUser;
//import com.plian.system.entity.sys.Message;
//import com.plian.system.mapper.mt.TemporaryTaskDistributionMapper;
//import com.plian.system.mapper.mt.TemporaryTaskUserMapper;
//import com.plian.system.mapper.sys.OrgMapper;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.config.exception.MyRuntimeException;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.mt.ITemporaryTaskDistributionService;
//import com.plian.system.service.mt.ITemporaryTaskUserService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.sys.message.IMessageService;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.service.sys.user.ISysUserService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.mt.FeedbackVO;
//import com.plian.system.vo.mt.TemporaryTaskDistributionVO;
//import com.plian.system.vo.mt.TemporaryTaskUrgeVO;
//import com.plian.system.vo.mt.TemporaryTaskUserVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import com.plian.system.wrapper.mt.TemporaryTaskDistributionWrapper;
//import com.plian.system.wrapper.mt.TemporaryTaskUserWrapper;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.flowable.ui.common.service.exception.BadRequestException;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.Assert;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.InputStream;
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.net.URLEncoder;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.BaseConstant.BASE64_KEY;
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//
///**
// * <p>
// * 临时任务下发 服务实现类
// * </p>
// *
// * @author hu song
// * @since 2023-02-07
// */
//@Slf4j
//@Service
//@RequiredArgsConstructor
//public class TemporaryTaskDistributionServiceImpl extends BaseServiceImpl<TemporaryTaskDistributionMapper, TemporaryTaskDistribution> implements ITemporaryTaskDistributionService, BaseFlowService {
//    private final TemporaryTaskDistributionMapper temporaryTaskDistributionMapper;
//    private final TemporaryTaskDistributionWrapper temporaryTaskDistributionWrapper;
//    private final ITemporaryTaskUserService temporaryTaskUserService;
//    private final FileService fileService;
//    private final TemporaryTaskUserMapper temporaryTaskUserMapper;
//    private final TemporaryTaskUserWrapper temporaryTaskUserWrapper;
//    private final FileDao fileDao;
//    private final TemporaryTaskUserWrapper temporaryTaskUnitWrapper;
//    private final OrgMapper orgMapper;
//    private final IMessageService messageService;
//    private final ISysUserService userService;
//    private final FormWorkflowService formWorkflowService;
//    private final IOrgService orgService;
//    private final UserDao userDao;
//
//    @Override
//    public ListResult<TemporaryTaskDistributionVO> findAll(Query query) {
//        List<SearchEntity> entityList = query.getSearch();
//        if (query.getAscs() == null && query.getDescs() == null) {
//            query.setDescs("create_time");
//        }
//        QueryWrapper<TemporaryTaskDistribution> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new TemporaryTaskDistribution()), entityList
//        );
////        TokenSearch<TemporaryTaskDistribution> tokenSearch = new TokenSearch<>();
////		tokenSearch.addTokenQuery(queryWrapper, query);
//
//        // 判断是国资数据还是企业数据
//        boolean isGzData = false;
//        String orgId = TokenUtil.getTokenOrgId();
//        if (query.getFlag() != null && query.getFlag() == 1) {
//            isGzData = orgService.checkIsGzw(orgId);
//        }
//
//        ListResult<TemporaryTaskDistributionVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//
//        if (isGzData) {
//            IPage<TemporaryTaskDistribution> page = page(Condition.getPage(query), queryWrapper);
//            listResult.setList(temporaryTaskDistributionWrapper.entityToVO(page.getRecords()));
//            listResult.setTotal(Long.valueOf(page.getTotal()).intValue());
//            // 交发处室
//            Map<Long, List<TemporaryTaskUser>> unitMap = new HashMap<>();
//            if (CollectionUtil.isNotEmpty(page.getRecords())) {
//                unitMap = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>()
//                                .in(TemporaryTaskUser::getTemporaryTaskId, page.getRecords().stream().map(TemporaryTaskDistribution::getId).collect(Collectors.toList())))
//                        .stream().collect(Collectors.groupingBy(TemporaryTaskUser::getTemporaryTaskId));
//            }
//
//            if (CollectionUtil.isNotEmpty(listResult.getList())) {
//                // 法律纠纷对应的所有用户
//                Map<Long, List<TemporaryTaskUser>> userMap = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>()
//                                .in(TemporaryTaskUser::getTemporaryTaskId, listResult.getList().stream().map(TemporaryTaskDistributionVO::getId).collect(Collectors.toList())))
//                        .stream().collect(Collectors.groupingBy(TemporaryTaskUser::getTemporaryTaskId));
//                for (TemporaryTaskDistributionVO vo : listResult.getList()) {
//                    // 计算收集进度。收集进度 = 已反馈/总交办用户
//                    List<TemporaryTaskUser> users = userMap.get(vo.getId());
//                    if (CollectionUtil.isNotEmpty(users)) {
//                        for (TemporaryTaskUser user : users) {
//                            if (StringUtil.isNotBlank(user.getContactNumber())) {
//                                user.setContactNumber(EncryptUtil.decryptBase64(user.getContactNumber(), BASE64_KEY));
//                            }
//                        }
//                        long feedbackCount = users.stream().filter(TemporaryTaskUser::getIsReport).count();
//                        vo.setCollectionProgress(BigDecimal.valueOf((double) feedbackCount / (double) users.size() * 100).setScale(0, RoundingMode.HALF_UP).toString() + "%");
//
//                        vo.setTemporaryTaskUserVos(temporaryTaskUnitWrapper.entityToVO(unitMap.get(vo.getId())));
//                    }
//                }
//            }
//        } else {
//            List<TemporaryTaskDistributionVO> taskVOS = Collections.emptyList();
//            // 企业
//            Map<Long, List<TemporaryTaskUser>> userMap = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>()
//                            .eq(TemporaryTaskUser::getUserId, TokenUtil.getTokenUserId()))
//                    .stream().collect(Collectors.groupingBy(TemporaryTaskUser::getTemporaryTaskId));
//            if (CollectionUtil.isNotEmpty(userMap)) {
//                queryWrapper.in("id", userMap.keySet());
//                queryWrapper.ne("task_status", "153001");
//
//                // 获取用户对应的任务并按照用户id分组
//                queryWrapper.orderByDesc("create_time");
//                taskVOS = temporaryTaskDistributionWrapper.entityToVO(new ArrayList<>(temporaryTaskDistributionMapper.selectList(queryWrapper)));
//                taskVOS.forEach(taskVO -> {
//                    List<TemporaryTaskUser> users = userMap.get(taskVO.getId());
//                    if (CollectionUtil.isNotEmpty(users)) {
//                        for (TemporaryTaskUser user : users) {
//                            if (StringUtil.isNotBlank(user.getContactNumber())) {
//                                user.setContactNumber(EncryptUtil.decryptBase64(user.getContactNumber(), BASE64_KEY));
//                            }
//                        }
//                    }
//                    taskVO.setTemporaryTaskUsers(users);
//                    taskVO.setTemporaryTaskUserVos(temporaryTaskUserWrapper.entityToVO(users));
//                });
//            }
//            listResult.setList(taskVOS);
//            listResult.setTotal(Long.valueOf(taskVOS.size()).intValue());
//        }
//        return listResult;
//    }
//
//    @Override
//    public TemporaryTaskDistributionVO detail(TemporaryTaskDistribution temporaryTaskDistribution) {
//        TemporaryTaskDistribution detail = getOne(Condition.getQueryWrapper(temporaryTaskDistribution));
//        TemporaryTaskDistributionVO result = temporaryTaskDistributionWrapper.entityToVO(detail);
//        if (result != null) {
//            List<TemporaryTaskUserVO> userVos = temporaryTaskUserWrapper.entityToVO(temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>().eq(TemporaryTaskUser::getTemporaryTaskId, result.getId())));
//            for (TemporaryTaskUserVO userVo : userVos) {
//                if (StringUtil.isNotBlank(userVo.getContactNumber())) {
//                    userVo.setContactNumber(EncryptUtil.decryptBase64(userVo.getContactNumber(), BASE64_KEY));
//                }
//            }
//            result.setTemporaryTaskUserVos(userVos);
//        }
//        return result;
//    }
//
//    @Override
//    public boolean saveOrUpdate(TemporaryTaskDistribution entity) {
//
//        boolean isSaveFlag = false;
//        if (Objects.isNull(entity.getId())) {
//            isSaveFlag = true;
//            entity.setCreateCompanyId(TokenUtil.getTokenOrgId());
//            entity.setInitiateTime(new Date());
//            String officeId = TokenUtil.getOfficeId();
//            entity.setOfficeId(StringUtils.isEmpty(officeId) ? null : Long.valueOf(officeId));
//            // 默认任务状态 任务状态: 未开始
//            entity.setTaskStatus("153001");
//            entity.setFormType(FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE + "");
//        } else {
//            if (Objects.nonNull(entity.getLimitTime()) && !Objects.equals("153001", entity.getTaskStatus())) {
//                if (DateUtil.now().before(entity.getLimitTime())) {
//                    entity.setTaskStatus("153002");
//                } else {
//                    entity.setTaskStatus("153003");
//                }
//            }
//            // 清空子表数据
//            temporaryTaskUserService.remove(Wrappers.lambdaQuery(TemporaryTaskUser.class).eq(TemporaryTaskUser::getTemporaryTaskId, entity.getId()));
//        }
//
//        boolean result = super.saveOrUpdate(entity);
//
//        if (isSaveFlag && Objects.equals(entity.getFormType(), FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE + "")) {
//            HashMap<String, Object> processVariable = new HashMap<>();
//            formWorkflowService.startProcessAndSimulate(String.valueOf(entity.getId()), entity.getFormType(), processVariable);
//        }
//        // 保存务交办用户
//        insertTemporaryTaskUser(entity.getTemporaryTaskUsers(), entity.getId());
//        // 附件
//        if (CollectionUtil.isNotEmpty(entity.getDocList())) {
//            if (isSaveFlag) {
//                fileService.saveAll(String.valueOf(entity.getId()), entity.getDocList());
//            } else {
//                fileService.edit(String.valueOf(entity.getId()), entity.getDocList());
//            }
//        }
//        return result;
//    }
//
//
//    /**
//     * 保存交办用户
//     *
//     * @param temporaryTaskUsers
//     * @param id
//     */
//    private void insertTemporaryTaskUser(List<TemporaryTaskUser> temporaryTaskUsers, Long id) {
//        if (CollectionUtil.isNotEmpty(temporaryTaskUsers)) {
//            List<TemporaryTaskUser> deletedUsers = temporaryTaskUserService.findDeletedUserByTemporaryIdAndUserIdIn(temporaryTaskUsers.stream().map(TemporaryTaskUser::getUserId).collect(Collectors.toSet()), id);
//            if (!deletedUsers.isEmpty()) {
//                // 把已删除的改成未删除
//                temporaryTaskUserService.updateDeletedFlagByIds(false, deletedUsers.stream().map(TemporaryTaskUser::getId).collect(Collectors.toSet()));
//                // 过滤掉已恢复的
//                temporaryTaskUsers = temporaryTaskUsers.stream().filter(item -> deletedUsers.stream().noneMatch(user -> Objects.equals(user.getUserId(), item.getUserId()))).collect(Collectors.toList());
//            }
//            if (CollectionUtil.isNotEmpty(temporaryTaskUsers)) {
//                temporaryTaskUsers.forEach(user -> {
//                    user.setIsReport(false);
//                    user.setTemporaryTaskId(id);
//                });
//                temporaryTaskUserService.saveOrUpdateBatch(temporaryTaskUsers.stream().filter(item -> item.getId() == null).collect(Collectors.toList()));
//            }
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean opinionFeedback(@Validated @RequestBody FeedbackVO vo) {
//        Assert.notEmpty(vo.getUserVos(), "反馈人信息不能为空");
//        TemporaryTaskUser user = Optional.ofNullable(temporaryTaskUserService.getById(vo.getUserVos().get(0).getId())).orElseThrow(() -> new BadRequestException("当前用户不存在可反馈的临时任务"));
//        user.setContent(vo.getTextContent());
//        user.setUserName(vo.getUserVos().get(0).getUserName());
//        user.setFeedbackTime(DateUtil.now());
//        return temporaryTaskUserService.saveOrUpdate(user);
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean fileCollectionFeedback(FeedbackVO vo) throws Exception {
//        Assert.notEmpty(vo.getDocList(), "反馈文件不能为空");
//        Assert.notEmpty(vo.getUserVos(), "反馈人信息不能为空");
//        TemporaryTaskUser user = Optional.ofNullable(temporaryTaskUserService.getById(vo.getUserVos().get(0).getId())).orElseThrow(() -> new BadRequestException("当前用户不存在可反馈的临时任务"));
//        fileDao.del_ParentId(user.getId() + "");
//        fileService.saveAll(String.valueOf(user.getId()), vo.getDocList());
//        user.setContent(JSON.toJSONString(vo.getDocList().stream().map(item -> item.get("id")).collect(Collectors.toList())));
//        user.setFeedbackTime(DateUtil.now());
//        user.setUserName(vo.getUserVos().get(0).getUserName());
//        return temporaryTaskUserService.saveOrUpdate(user);
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public ReportReturnVO dataCollectionFeedback(FeedbackVO vo) {
//        Assert.notEmpty(vo.getUserVos(), "反馈人信息不能为空");
//        TemporaryTaskUser user = Optional.ofNullable(temporaryTaskUserService.getById(vo.getUserVos().get(0).getId())).orElseThrow(() -> new BadRequestException("当前用户不存在可反馈的临时任务"));
//        // 对值为数字列的求和
//        ReportReturnVO reportReturnVO = vo.getReportReturnVO();
//        /*Map<String, Object> totalMap = new HashMap<>();
//        for (Object dataObj : reportReturnVO.getGrids().getData()) {
//            Map<String, Object> dataMap = (Map<String, Object>) dataObj;
//            dataMap.forEach((key, value) -> {
//                if (Objects.nonNull(value) && StringUtils.isNumeric(value.toString())) {
//                    if ("excelRowNum".equals(key)) {
//                        totalMap.put("总计", "/");
//                    } else {
//                        // 对列求和
//                        totalMap.put(key, Objects.isNull(totalMap.get(key)) ? "0" : (NumberUtil.toInt(totalMap.get(key).toString(), 0) + NumberUtil.toInt(value.toString(), 0)));
//                    }
//                } else {
//                    totalMap.put(key, "/");
//                }
//            });
//        }
//        log.info("数据收集反馈计算总计后:{}", JSON.toJSONString(reportReturnVO));
//        // 添加总计行
//        reportReturnVO.getGrids().getData().add(totalMap);*/
//        user.setContent(JSON.toJSONString(reportReturnVO));
//        user.setFeedbackTime(DateUtil.now());
//        user.setUserName(vo.getUserVos().get(0).getUserName());
//        temporaryTaskUserService.saveOrUpdate(user);
//
//        if (CollectionUtil.isNotEmpty(vo.getDocList())) {
//            // 保存附件
//            fileService.saveAll(user.getId() + "", vo.getDocList());
//        }
//        return reportReturnVO;
//
//    }
//
//    /**
//     * 处理excel的内容
//     *
//     * @return
//     */
//    private ReportReturnVO handlerExcelContent(InputStream inputStream) {
//        // 读取文件内容
//        ExcelImportResult<Map<String, Object>> objectExcelImportResult;
//        try {
//            // 读取文件内容
//            objectExcelImportResult = ExcelImportUtil.importExcelMore(inputStream, Map.class, new ImportParams());
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new MyRuntimeException("解析数据收集反馈文件错误");
//        }
//        List<Map<String, Object>> list = objectExcelImportResult.getList();
//        Workbook book = objectExcelImportResult.getFailWorkbook();
//        Row row = book.getSheetAt(0).getRow(0);
//        Iterator<Cell> cellIterator = row.iterator();
//
//        // 标题和key映射map
//        Map<String, Object> titleMap = new HashMap<>();
//        titleMap.put("序号", "excelRowNum");
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//        ReportVO reportVO = new ReportVO();
//        reportVO.addHeader(HeaderVO.builder().key("excelRowNum").title("序号").build());
//        while (cellIterator.hasNext()) {
//            Cell cell = cellIterator.next();
//            // 标题名字
//            String name = cell.getStringCellValue();
//            // 标题对应的列号
//            int columnIndex = cell.getColumnIndex();
//            // 把中文标题转换成英文key 例如: zhangsan_A代表excel A列的标题叫张三
//            String pinyinName = "";
//            try {
//                pinyinName = PingyinUtil.toPinyin(name) + "_";
//            } catch (Exception e) {
//            }
//            titleMap.put(name, pinyinName + getTitle(columnIndex));
//            reportVO.addHeader(HeaderVO.builder().key(titleMap.get(name).toString()).title(name).build());
//        }
//        // 存储数据的集合
//        List<Map<String, Object>> datas = new ArrayList<>();
//        for (Map<String, Object> dataMap : list) {
//            Map<String, Object> dm = new HashMap<>();
//            for (String k : dataMap.keySet()) {
//                // 中文标题对应的英文标题
//                String key = Objects.nonNull(titleMap.get(k)) ? titleMap.get(k).toString() : k;
//                dm.put(key, dataMap.get(k));
//            }
//            datas.add(dm);
//        }
//        reportVO.setData(datas);
//        reportReturnVO.setGrids(reportVO);
//        log.info("数据收集反馈处理后的模版数据:{}", JSONObject.toJSONString(reportReturnVO));
//        return reportReturnVO;
//    }
//
//    /**
//     * 获取excel列标题
//     *
//     * @param columnIndex
//     * @return
//     */
//    private String getTitle(int columnIndex) {
//        columnIndex = columnIndex + 65;
//        if (65 <= columnIndex && columnIndex <= 90) {
//            return String.valueOf((char) columnIndex);
//        } else if (91 <= columnIndex && columnIndex <= 116) {
//            return "A" + (char) (columnIndex - 26);
//        } else {
//            return "column" + columnIndex;
//        }
//    }
//
//    @Override
//    public void export(Long taskId, List<TemporaryTaskUserVO> userVos, HttpServletResponse response) {
//        if (taskId != null) {
//            List<TemporaryTaskUser> users = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>().eq(TemporaryTaskUser::getTemporaryTaskId, taskId));
//            userVos = temporaryTaskUserWrapper.entityToVO(users);
//        }
//
//        for (int i = 0; i < userVos.size(); i++) {
//            TemporaryTaskUserVO vo = userVos.get(i);
//            // id字段变成序号
//            vo.setNumber((i + 1) + "");
//        }
//        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//        response.setCharacterEncoding("utf-8");
//        // 这里URLEncoder.encode可以防止中文乱码
//        String fileName = null;
//        try {
//            fileName = URLEncoder.encode("意见反馈_" + DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME), "UTF-8").replaceAll("\\+", "%20");
//
//            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
//            EasyExcel.write(response.getOutputStream(), TemporaryTaskUserVO.class)
//                    .sheet("意见反馈")
//                    .doWrite(userVos);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean delete(List<String> ids) {
//        // 删除子表
//        temporaryTaskUserService.removeByIds(ids);
//        return deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)));
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public boolean issued(Long taskId) throws Exception {
//        String userId = TokenUtil.getTokenUserId();
//        PageData findbyid = userDao.findbyid(userId);
//        String userName = findbyid.getString("name");
//        TemporaryTaskDistribution taskDistribution = Optional.ofNullable(temporaryTaskDistributionMapper.selectById(taskId)).orElseThrow(() -> new BadRequestException("临时任务不存在"));
//        if (!"153001".equals(taskDistribution.getTaskStatus())) {
//            throw new BadRequestException("当前任务状态不支持此操作");
//        }
//        // 修改任务状态
//        if (DateUtil.now().before(taskDistribution.getLimitTime())) {
//            taskDistribution.setTaskStatus("153002");
//        } else {
//            taskDistribution.setTaskStatus("153003");
//        }
//        boolean result = updateById(taskDistribution);
//        List<TemporaryTaskUser> users = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>().eq(TemporaryTaskUser::getTemporaryTaskId, taskId));
//        List<TemporaryTaskUserVO> userVos = temporaryTaskUserWrapper.entityToVO(users);
//        if (CollectionUtil.isNotEmpty(userVos)) {
//            List<Message> messages = new ArrayList<>();
//            for (TemporaryTaskUserVO userVO : userVos) {
//                Message message = Message.builder()
//                        .formId(taskDistribution.getId() + "")
//                        .orgName(userVO.getUnitName())
//                        .orgId(userVO.getUnitId())
//                        .formType("" + FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE)
//                        .formTypeName("临时任务下发")
//                        .sendUser(userId)
//                        .isIgnore(0)
//                        .sendUserName(userName)
//                        .messageTime(DateUtil.now())
//                        .createUser(userVO.getUserId())
//                        .message("您有一个临时工作任务需反馈")
//                        .build();
//                messages.add(message);
//            }
//            messageService.saveBatch(messages);
//        }
//        return result;
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void urge(TemporaryTaskUrgeVO vo) throws Exception {
//        String userId = TokenUtil.getTokenUserId();
//        PageData findbyid = userDao.findbyid(userId);
//        String userName = findbyid.getString("name");
//        TemporaryTaskDistribution taskDistribution = temporaryTaskDistributionMapper.selectById(vo.getTaskId());
//        if (Objects.nonNull(taskDistribution)) {
//            if (!"153002".equals(taskDistribution.getTaskStatus())) {
//                throw new BadRequestException("当前任务状态不支持此操作");
//            }
//            // 修改任务状态
//            if (DateUtil.now().before(taskDistribution.getLimitTime())) {
//                taskDistribution.setTaskStatus("153002");
//            } else {
//                taskDistribution.setTaskStatus("153003");
//            }
//            updateById(taskDistribution);
//
//            List<TemporaryTaskUser> users = temporaryTaskUserMapper.selectList(new LambdaQueryWrapper<TemporaryTaskUser>().eq(TemporaryTaskUser::getTemporaryTaskId, vo.getTaskId()).in(TemporaryTaskUser::getUserId, vo.getUserIds()));
//            if (CollectionUtil.isNotEmpty(users)) {
//                for (TemporaryTaskUser user : users) {
//                    TemporaryTaskUserVO userVO = temporaryTaskUserWrapper.entityToVO(user);
//                    Message message = Message.builder()
//                            .formId(taskDistribution.getId() + "")
//                            .orgName(userVO.getUnitName())
//                            .orgId(userVO.getUnitId())
//                            .sendUser(userId)
//                            .sendUserName(userName)
//                            .isIgnore(0)
//                            .formType("" + FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE)
//                            .formTypeName("临时任务下发")
//                            .messageTime(DateUtil.now())
//                            .createUser(userVO.getUserId())
//                            .message("您有一个临时工作任务未反馈")
//                            .build();
//                    messageService.save(message);
//                }
//            }
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public ReportReturnVO importTemplate(MultipartFile file) {
//        try {
//            ReportReturnVO reportReturnVO = handlerExcelContent(file.getInputStream());
//            return reportReturnVO;
//        } catch (IOException e) {
//            e.printStackTrace();
//            throw new BadRequestException("模版导入错误");
//        }
//    }
//
//    @Override
//    public void exportTemplate(ReportReturnVO reportReturnVO, HttpServletResponse response) {
//        // 标题
//        List<List<String>> titleList = new ArrayList<>();
//
//        for (HeaderVO header : reportReturnVO.getGrids().getHeader()) {
//            if (header.getKey().contains("_")) {
//                titleList.add(Arrays.asList(header.getTitle()));
//            }
//        }
//
//        if (titleList.size() > 0) {
//            try {
//                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//                response.setCharacterEncoding("utf-8");
//                // 这里URLEncoder.encode可以防止中文乱码
//                String fileName = "数据反馈模版导出.xlsx";
//                response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName);
//                EasyExcel.write(response.getOutputStream()).head(titleList).sheet("数据反馈").doWrite(new ArrayList<>());
//            } catch (IOException e) {
//                throw new BadRequestException("导出模版错误");
//            }
//        }
//
//    }
//
//    @Override
//    public HashMap<String, Object> commit(String id) {
//        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW);
//
//        //将需要提交的流程变量返回，用于工作流侧
//        return new HashMap<String, Object>();
//    }
//
//    @Override
//    public Boolean finish(String id) {
//        return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH);
//    }
//
//
//    @Override
//    public Boolean reject(String id, int formState, String comment) {
//        return handleStatus(Long.valueOf(id), formState);
//    }
//
//    @Override
//    public List<PageData> findByIds(List<String> formIds) {
//        LambdaQueryWrapper<TemporaryTaskDistribution> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.in(TemporaryTaskDistribution::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//        List<TemporaryTaskDistribution> temporaryTaskDisputes = list(queryWrapper);
//        List<TemporaryTaskDistributionVO> lawDisputeVOS = temporaryTaskDistributionWrapper.entityToVO(temporaryTaskDisputes);
//        List<PageData> pageDataList = new ArrayList<>();
//        try {
//            if (CollectionUtil.isNotEmpty(lawDisputeVOS)) {
//                for (TemporaryTaskDistributionVO vo : lawDisputeVOS) {
//                    PageData pd = new PageData();
//                    pd.put("id", vo.getId());
//                    pd.put("UNITNAME", vo.getFillingUnitName());
//                    pd.put("APPLICANTNAME", vo.getCreateUserName());
//                    pd.put("applicantId", vo.getCreateUser());
//                    pd.put("applyOrganizationId", vo.getFillingUnitId());
//                    pd.put("formType", FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE);
//                    pd.put("orgName", vo.getFillingUnitName());
//                    pageDataList.add(pd);
//                }
//            }
//
//            return pageDataList;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//        return pageDataList;
//    }
//
//    @Override
//    public List<Integer> getFormType() {
//        return Arrays.asList(FormTypeConstant.MT_TEMPORARY_TASK_DISTRIBUTION_ENTERPRISE);
//    }
//
//    @Override
//    public void goBackToStash(String formId) {
//        handleStatus(Long.valueOf(formId), UNREVIEWED);
//    }
//
//    /**
//     * 统一处理状态机事件方法
//     *
//     * @param id           主键
//     * @param updateStatus 更新状态
//     * @return boolean
//     */
//    private Boolean handleStatus(Long id, int updateStatus) {
//        try {
//            TemporaryTaskDistribution tempTaskDistribution = getById(id);
//            /**
//             * 设置审批人和审批时间
//             */
//            if (updateStatus == FormStatusConstant.FINISH) {
//                tempTaskDistribution.setApprovedUser(TokenUtil.getTokenUserId());
//                Date now = DateUtil.now();
//                tempTaskDistribution.setApprovedTime(now);
//            }
//            tempTaskDistribution.setStatus(updateStatus);
//            updateById(tempTaskDistribution);
//            return true;
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return false;
//        }
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void report(Long temporaryUserId, Boolean isReport) {
//        TemporaryTaskUser user = Optional.ofNullable(temporaryTaskUserService.getById(temporaryUserId)).orElseThrow(() -> new BadRequestException("反馈记录不存在"));
//        user.setIsReport(isReport);
//        temporaryTaskUserService.updateById(user);
//    }
//}
